From 9476022dc22304cd363111e4b4c5e584f3d89fd0 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:56:45 -0600 Subject: [PATCH] fix faulty assertion in garmin. (#1290) the '-' character is legal for some devices, but was excluded in the assertions as it can be a metacharacter. --- garmin.cc | 25 ++++++++++--------------- garmin.h | 3 +-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/garmin.cc b/garmin.cc index 5c1b8c0ef..732f12b09 100644 --- a/garmin.cc +++ b/garmin.cc @@ -21,17 +21,18 @@ #include "garmin.h" -#include // for assert #include // for INT_MAX #include // for atan2, floor, sqrt #include // for fprintf, fflush, snprintf, snprintf +#include // for int32_t #include // for strtol #include // for memcpy, strlen, strncpy, strchr #include // for time_t #include // for as_const #include // for QByteArray -#include // for QRegularExpression +#include // for QChar +#include // for QList<>::const_iterator #include // for QString #include // for QTextCodec #include // for CaseInsensitive @@ -46,7 +47,6 @@ #include "jeeps/gpsapp.h" // for GPS_Set_Baud_Rate, GPS_Init, GPS_Pre... #include "jeeps/gpscom.h" // for GPS_Command_Get_Lap, GPS_Command_Get... #include "jeeps/gpsmem.h" // for GPS_Track_Del, GPS_Way_Del, GPS_Pvt_Del -#include "jeeps/gpsport.h" // for int32 #include "jeeps/gpsprot.h" // for gps_waypt_type, gps_category_type #include "jeeps/gpssend.h" // for GPS_SWay, GPS_PWay, GPS_STrack, GPS_... #include "jeeps/gpsserial.h" // for DEFAULT_BAUD @@ -297,17 +297,7 @@ GarminFormat::rw_init(const QString& fname) fprintf(stdout, "receiver charset detected as %s.\r\n", receiver_charset); } - /* - * Beware, valid_waypt_chars shouldn't contain any character class metacharacters, - * i.e. '\', '^', '-', '[', or ']' - */ - assert(!QString(valid_waypt_chars).contains('\\')); - assert(!QString(valid_waypt_chars).contains('^')); - assert(!QString(valid_waypt_chars).contains('-')); - assert(!QString(valid_waypt_chars).contains('[')); - assert(!QString(valid_waypt_chars).contains(']')); - invalid_char_re = QRegularExpression(QStringLiteral("[^%1]").arg(valid_waypt_chars)); - assert(invalid_char_re.isValid()); + valid_chars = valid_waypt_chars; } void @@ -330,6 +320,8 @@ GarminFormat::rw_deinit() xfree(portname); portname = nullptr; + + valid_chars = QString(); } int @@ -958,7 +950,10 @@ GarminFormat::route_waypt_pr(const Waypoint* wpt) * for the new models, we just release this safety check manually. */ if (receiver_must_upper) { - cleanname = cleanname.toUpper().remove(invalid_char_re); + auto isInvalidChar = [this](const QChar &ch)->bool { + return !valid_chars.contains(ch); + }; + cleanname = cleanname.toUpper().removeIf(isInvalidChar); } write_char_string(rte->ident, str_from_unicode(cleanname).constData(), diff --git a/garmin.h b/garmin.h index 0139a861d..68d42bbfb 100644 --- a/garmin.h +++ b/garmin.h @@ -24,7 +24,6 @@ #include // for size_t #include // for QByteArray -#include // for QRegularExpression #include // for QString #include // for QTextCodec #include // for QVector @@ -135,7 +134,7 @@ private: bool receiver_must_upper = true; QTextCodec* codec{nullptr}; - QRegularExpression invalid_char_re; + QString valid_chars; QVector garmin_args = { { -- 2.30.2